package com.linemanage.daoimpl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.RowMapper;

import com.linemanage.bean.BusInfo;
import com.linemanage.dao.BuseInfoDao;

public class BusInfoDaoImpl extends BaseDaoImpl implements BuseInfoDao{

	private RowMapper<BusInfo> busInfoMapper=new RowMapper<BusInfo>() {
		
		@Override
		public BusInfo mapRow(ResultSet rs, int arg1) throws SQLException {
			BusInfo busInfo=new BusInfo();
			busInfo.setBusId(rs.getString("bus_id"));
			busInfo.setBusType(rs.getInt("bus_type"));
			busInfo.setPeopleNum(rs.getInt("people_num"));
			busInfo.setLineId(rs.getString("line_id"));
			return busInfo;
		}
	};
	@Override
	public boolean addOne(BusInfo t) {
		return jdbcTemplate.update("insert into bus_info values(?,?,?,?)", t.getBusId(),t.getBusType(),
				t.getPeopleNum(),t.getLineId())>0;
	}

	@Override
	
	public boolean deleteOne(String id) {
		return jdbcTemplate.update("delete from bus_info where bus_id=?", id)>0;
	}


	@Override
	public boolean editOne(BusInfo t) {
		return jdbcTemplate.update("update bus_info set bus_type=?,people_num=?,line_id=? where bus_id=?",
				t.getBusType(),t.getPeopleNum(),t.getLineId(),t.getBusId())>0;
	}

	@Override
	public BusInfo searchOne(String id) {
		return jdbcTemplate.queryForObject("select * from bus_info where bus_id=?", busInfoMapper,id);
	}

	@Override
	public List<BusInfo> searchAll(int offset, int end) {
		return jdbcTemplate.query("select * from bus_info limit "+offset+","+end, busInfoMapper);
	}

	@Override
	public Integer searchAllCount() {
		return jdbcTemplate.queryForInt("select count(1) from bus_info");
	}


}
